<template>
  <div>
    <RegisterHeader />
    <div class="list">
      <form action="" method="get">
        <div class="account-number">
          <input
            type="text"
            placeholder="邮箱/手机/用户名"
            v-model="username"
            @blur="phoneRegular"
          />
          <p class="p1" v-if="isShow0">请输入正确的账号</p>
        </div>
        <div class="password">
          <input
            type="password"
            placeholder="密码"
            v-model="pass"
            @blur="passRegular"
          />
          <p class="p1" v-if="isShow2">!长度应为6-20位字符</p>
        </div>
        <div class="confirm-password">
          <input
            type="password"
            placeholder="确认密码"
            v-model="confirmpass"
            @blur="confirmRegular"
          />
          <p class="p1" v-if="isShow3">两次密码不一致</p>
        </div>
        <div class="xieyi">
          <input type="checkbox" checked="checked" value="1" />
          我已阅读并接受《3YX服务网使用协议》
        </div>
        <div class="submit">
          <input type="submit" value="注册" @click="submit" />
        </div>
      </form>
    </div>
    <div class="w-Mfoot">
      <p>
       <router-link to="/login">登录</router-link>
        <em>|</em>
        <router-link to="/register">注册</router-link>
        <em>|</em>
        <a href="">忘记密码</a>
        <em>|</em>
        <a href="">帮助</a>
        <em>|</em>
        <a href="">电脑版</a>
      </p>
      <p class="w-copyright">©3yx.com</p>
    </div>
  </div>
</template>
 
<script>
import { userReg } from "../api/user";
import RegisterHeader from "../components/Register-Header.vue";
export default {
  data() {
    return {
      username: "",
      pass: "",
      confirmpass: "",
      isShow0: false,
      isShow2: false,
      isShow3: false,
    };
  },
  components: {
    RegisterHeader,
  },
  methods: {
    phoneRegular() {
      if (this.username == "") {
        this.isShow0 = true;
      } else {
        this.isShow0 = false;
      }
    },
    passRegular() {
      // console.log(this.pass);
      if (this.pass == "") {
        this.isShow2 = true;
        return;
      } else {
        this.isShow2 = false;
      }
    },
    confirmRegular() {
      if (this.pass != this.confirmpass) {
        this.isShow3 = true;
      } else {
        this.isShow3 = false;
      }
    },
    submit() {
      var Formmag = {
        username: this.username,
        pass: this.pass,
      };
      if (this.isShow0 == false &&this.isShow2 == false &&this.isShow3 == false) {
        userReg(Formmag).then(res=>{
          // console.log(res);
          if(res){
            this.$router.push('/login')
          }
        });

      }else {
                console.log('error submit!!');
                return false;
            }
    },
  },
};
</script>

<style lang="less" scoped>
.list {
  form {
    // color: #666;
    .account-number {
      input {
        display: block;
        width: 96%;
        height: 45px;
        margin: 10px auto;
        border: 1px solid #d6d6d6;
        font-size: 14px;
        font-family: "microsoft YaHei";
        -webkit-box-sizing: border-box;
        background: #fff url("../assets/img/w_inputbg.png") no-repeat;
        background-position: 8px 12px;
        padding: 0 0 0 40px;
        // margin: 10px 0;
      }
      input:focus {
        background-position: 8px -74px;
      }
    }
    .xieyi {
      text-align: center;
      color: #666;
      margin-bottom: 20px;
      margin-top: 15px;
      font-size: 12px;
      input {
        margin: 0;
        padding: 0;
      }
    }
    .password {
      //   background: #fff url("../assets/img/w_inputbg.png") no-repeat;
      //   background-position: 8px 12px;
      input {
        display: block;
        width: 96%;
        height: 45px;
        margin: 10px auto;
        border: 1px solid #d6d6d6;
        font-size: 14px;
        font-family: "microsoft YaHei";
        -webkit-box-sizing: border-box;
        background: #fff url("../assets/img/w_inputbg.png") no-repeat;
        background-position: 8px -33px;
        padding: 0 0 0 40px;
        // margin: 10px 0;
      }
      input:focus {
        background-position: 8px -127px;
      }
    }
    .submit {
      input {
        display: block;
        width: 96%;
        background: #e2574c;
        color: #fff;
        height: 40px;
        margin: 10px auto 10px auto;
        border-radius: 5px;
        text-align: center;
        line-height: 40px;
        font-size: 1em;
        border: 0px;
      }
    }
    .confirm-password {
      input {
        display: block;
        width: 96%;
        height: 45px;
        margin: 10px auto;
        border: 1px solid #d6d6d6;
        font-size: 14px;
        font-family: "microsoft YaHei";
        -webkit-box-sizing: border-box;
        background: #fff url("../assets/img/w_inputbg.png") no-repeat;
        background-position: 8px -33px;
        padding: 0 0 0 40px;
      }
      input:focus {
        background-position: 8px -127px;
      }
    }
  }
}
.w-Mfoot {
  text-align: center;
  bottom: 0;
  width: 100%;
  p {
    em {
      padding: 0 8px;
    }
    a {
      color: #666;
      font-size: 12px;
    }
  }
  .w-copyright {
    font-size: 12px;
    color: #666;
    // font-size: 1.2em;
    padding: 5px 0 10px 0;
  }
}
.p1 {
  font-size: 12px;
  padding-left: 10px;
  color: orange;
}
</style>